package com.lm.services.hibernate.plane;

import java.util.List;

import com.lm.entity.bean.PlanItinerary;
import com.lm.services.iface.plane.IPlanItineraryService;
import com.lm.utils.Tools;
import com.lm.utils.page.PageBean;
import com.lm.utils.page.Paginate;

public class PlanItineraryService extends Paginate implements
		IPlanItineraryService {

	@Override
	public List getList(PlanItinerary item, PageBean pb) {
		StringBuffer hql = new StringBuffer();
		if (Tools.isNotNullOrEmpty(item.getStatusDesc())) {
			hql.append("AND status=").append(item.getStatusDesc());
		}
		if (Tools.isNotNullOrEmpty(item.getStartTime())) {
			hql.append("AND creatTime >='").append(item.getStartTime()).append(" 00:00:00'");
		}
		if (Tools.isNotNullOrEmpty(item.getEndTime())) {
			hql.append("AND creatTime <='").append(item.getEndTime()).append(" 23:59:59'");
		} 
		List<PlanItinerary> list = null;
		if(Tools.isNotNullOrEmpty(hql)){
			if(pb.isShowPageToolsMenu()){	
				pb.setTotalCountSQL("SELECT COUNT(*) FROM PlanItinerary WHERE 1=1 "
						+ hql.toString());
			}
			hql.insert(0, "FROM PlanItinerary where 1=1 ").append(" order by creatTime ").append(pb.getSort());
			pb.setListSQL(hql.toString());
		try {
			list = getList(pb);
			if(pb.isShowPageToolsMenu()){	
				pb.setCount(getTotalCount(pb).intValue());
				pb.setPageToolsMenu(getToolsMenu(pb));
			}
			} catch (Exception e) {}
		}
		return list;
	}

	@Override
	public void updateParentOrder(PlanItinerary item) {
		StringBuffer hql = new StringBuffer();
		hql.append("update PlanItinerary set status =")
				.append(item.getStatus()).append("where id=")
				.append(item.getId());
		onExecuteHQLUpdate(hql.toString());
	}
}
